home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8533 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  53 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: razine@aol.com (Razine)
  3. Newsgroups: comp.lang.c
  4. Subject: revised code of calling a function twice from printf
  5. Date: 4 Mar 1996 17:51:16 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4hfs54$k4e@newsbf02.news.aol.com>
  9. Reply-To: razine@aol.com (Razine)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. Here is the actual code , modified with everyone's suggestions.  However
  13. there is still a bug in here somewhere.  Can anyone please explain what is
  14. wrong with this.
  15.  
  16. It returns 
  17.  
  18. [1] NONE       [2] NE
  19.  
  20. I would like it to return
  21.  
  22. [1] NONE       [2] Asprin
  23.  
  24. Thank you very much for your help.  it is greatly appreciated.
  25.  
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29.  
  30. char *display_drug_type(int drug_index);
  31.  
  32. int drug_inventory[5]={0,1,0,0,0};
  33.  
  34. int main() {
  35.  
  36.     printf("[1] %s             [2] %s  
  37. \n",display_drug_type(0),display_drug_type(1));
  38.  
  39. return 0;
  40.         }
  41.  
  42. char *display_drug_type(int drug_index) {
  43.    char drug_type[81]="\0";
  44.  
  45.    switch(drug_inventory[drug_index]) {
  46.      case 0 : strcpy(drug_type,"NONE"); break;
  47.      case 1 : strcpy(drug_type,"Asprin"); break;
  48.      default : printf("Error in Display_drug_inventory");
  49.                         }
  50.    return drug_type;
  51. }
  52.  
  53.